package com.ffzx.commerce.framework.common.persistence;

import java.io.Serializable;
import java.util.Map;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import com.ffzx.commerce.framework.annotation.Comment;
import com.google.common.collect.Maps;

/**
 * 基础实体对象
 * 
 * @author zhugj
 * @date 2016年3月1日 下午2:03:29
 * @version 0.1.0
 */
public abstract class BaseEntity<T> implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 删除标记（0：正常；1：删除；）
	 */
	public static final String DEL_FLAG_NORMAL = "0";
	public static final String DEL_FLAG_DELETE = "1";
	
	/**
	 * 实体编号（唯一标识）
	 */
	@Comment("主键")
	protected String id;
	
	/**
	 * 自定义SQL（SQL标识，SQL内容）
	 */
	protected Map<String, String> sqlMap;
	
	public BaseEntity() {
		
	}
	
	public BaseEntity(String id) {
		this();
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public Map<String, String> getSqlMap() {
		if (sqlMap == null){
			sqlMap = Maps.newHashMap();
		}
		return sqlMap;
	}

	public void setSqlMap(Map<String, String> sqlMap) {
		this.sqlMap = sqlMap;
	}
	
	@Override
    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!getClass().equals(obj.getClass())) {
            return false;
        }
        BaseEntity<?> that = (BaseEntity<?>) obj;
        return null == this.getId() ? false : this.getId().equals(that.getId());
    }
    
//    @Override
//    public String toString() {
//    	
//        return ReflectionToStringBuilder.toString(this);
//    }
}
